<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>密码框</title>
    <style type="text/css">
    div{
        width: 600px;
        margin: 100px auto;
    }
        .massage{
            background-image: url(gth.png);
            background-repeat:no-repeat;
            background-position: left center;
            color:black;
            display: inline-block;
            padding-left: 20px;
        } 
        .right{
            background-image: url(right.png);
            background-repeat: no-repeat;
            color: green;
        }
        .wrong{
            background-repeat: no-repeat;
            background-image: url(wrong.png);
            color: red;
        }
    </style>
</head>
<body>
    <div class="register">
    <input type="password" id="pwd">
    <p class="massage">请输入6-16位密码</p>
    </div>
    <script>
        var pwd=document.querySelector('#pwd'); 
        var aa=document.querySelector('.massage');
        pwd.onblur= function(){
             if(this.value.length>16 || this.value.length<6){
                 aa.innerText='错误，请输入6-16为密码';
                 aa.className='massage wrong';
             }else{
                aa.className='massage right';
                aa.innerText='密码正确';  
             }
        }
    </script>
</body>
</html>
